﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using WebGrease.Css.Extensions;
using ZTreeDome.Util;
using ZTreeDome.ViewModel;

namespace ZTreeDome.Controllers
{
    public class ZTreeController : Controller
    {
        // GET: ZTree
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetPosition()
        {
            string sql = "SELECT id,Name,'1' isParent FROM dbo.Position";
            DataTable dt = SqlUtil.GetDataTable(SqlUtil.connString, sql, CommandType.Text);
            List<ZTreeModel> result = new List<ZTreeModel>();
            dt.AsEnumerable().ForEach(x =>
            {
                ZTreeModel tree = new ZTreeModel();
                tree.id = x.Field<Int32>("id").ToString();
                tree.name = x.Field<string>("Name");
                tree.isParent = x.Field<string>("isParent") == "1" ? true : false;
                tree.ParentId = 0;
                result.Add(tree);
            });
            return Json(JsonConvert.SerializeObject(result), "text/html", JsonRequestBehavior.AllowGet);
        }


        public ActionResult GetData()
        {

            return View();
        }
    }
}